#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;



int main() {
    int n, x;
    cin >> n >> x;
    priority_queue<int, vector<int>, greater<int>> q;
    while (n--)
    {
        int k;
        cin >> k;
        q.push(k);
    }
    int i = 0;
    long long ret = 0;
    while (q.size() > x)
    {
        i++;
        while (q.top() == i)
        {
            q.pop();
        }
    }
    ret += (i * x);
    while (q.size())
    {
        ret += q.top() - i;
        q.pop();
    }
    cout << ret << endl;
    return 0;
}


#include <unordered_set>

int k, t;
int ret = 1e5 + 10;
unordered_set<long long> row;
unordered_set<long long> col;
unordered_set<long long> dig1;
unordered_set<long long> dig2;

int main() {
    cin >> k;
    for (int i = 1; i <= k; i++)
    {
        int x, y;
        cin >> x >> y;
        if (ret != 1e5 + 10)
        {
            continue;
        }
        if (row.count(y) || col.count(x) || dig1.count(y - x) || dig2.count(y + x))
        {
            ret = i;
        }
        row.insert(y);
        col.insert(x);
        dig1.insert(y - x);
        dig2.insert(y + x);
    }
    cin >> t;
    while (t--)
    {
        int i;
        cin >> i;
        if (i >= ret)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

const int N = 1010;
const int M = 110;

int n, k;
int arr[N];
int f[N][M];
int g[N][M];

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int j = 0; j <= k; j++)
    {
        f[0][j] = g[0][j] = -0x3f3f3f3f;
    }
    f[0][0] = -arr[0];
    g[0][0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            f[i][j] = max(f[i - 1][j], g[i - 1][j] - arr[i]);
            g[i][j] = g[i - 1][j];
            if (j >= 1)
            {
                g[i][j] = max(g[i][j], f[i - 1][j - 1] + arr[i]);
            }
        }
    }
    int ret = 0;
    for (int j = 0; j <= k; j++)
    {
        ret = max(ret, g[n - 1][j]);
    }
    cout << ret << endl;
    return 0;
}


class Solution {
public:
    int arr[110] = { 0 };
    int dp[110][110] = { 0 };

    int getCoins(vector<int>& coins) {
        // write code here
        int n = coins.size();
        arr[0] = arr[n + 1] = 1;
        for (int i = 1; i <= n; i++)
        {
            arr[i] = coins[i - 1];
        }
        for (int i = n; i >= 1; i--)
        {
            for (int j = i; j <= n; j++)
            {
                for (int k = j; k <= n; k++)
                {
                    dp[i][j] = max(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + arr[i - 1] * arr[k] * arr[j + 1]);
                }
            }
        }
        return dp[1][n];
    }
};